//package com.sjf.batch.demo;
//
//import cn.hutool.core.util.ObjectUtil;
//import com.sjf.batch.mapper.RequestLogMapper;
//import com.sjf.batch.pojo.dto.requestDtoLog;
//import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.annotation.*;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.core.annotation.Order;
//import org.springframework.stereotype.Component;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.xml.ws.Response;
//import java.util.Arrays;
//
///**
// * @author <huangtang>
// * @since 2022/1/17 9:12
// **/
//@Aspect
//@Component
//public class LogAspect {
//
//    private static final Logger logger = LoggerFactory.getLogger(LogAspect.class);
//
//    ThreadLocal<Long> startTime = new ThreadLocal<>();
//
//    @Autowired
//    RequestLogMapper logMapper;
//
//    /**
//     * 需要增强的方法及接口
//     */
//    @Pointcut("execution(public * com.sjf.batch.controller.*.*(..))")
//    @Order(2)
//    public void pointCut() {
//    }
//
//    //@Pointcut("@annotation(com.sjf.batch.annotation.RedisCache)")
//    //@Order(1)
//    //public void annotationPoint(){}
//
//    @Before(value = "pointCut()")
//    public void before(JoinPoint joinPoint) {
//        System.out.println("-----------方法执行前-----------");
//        ServletRequestAttributes attribute = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        assert attribute != null;
//        HttpServletRequest request = attribute.getRequest();
//        logger.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
//        logger.info("请求来源=>" + request.getRemoteAddr());
//        logger.info("请求URL=>" + request.getRequestURL());
//        logger.info("请求方法=>" + request.getMethod());
//        logger.info("响应方法=>" + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
//        logger.info("请求参数=>" + Arrays.toString(joinPoint.getArgs()));
//        logger.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
//        requestDtoLog logDto = new requestDtoLog ();
//        logDto.setRemoteAddr (request.getRemoteAddr ());
//        logDto.setRequestUrl (request.getRequestURL ().toString ());
//        logDto.setRequestMethod (request.getMethod ());
//        logDto.setResponseMethod (joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
//        logDto.setRequestArgs (Arrays.toString (joinPoint.getArgs ()));
//        logMapper.insert (logDto);
//
//    }
//
//    @Around("pointCut() && args(arg)")
//    public String around(ProceedingJoinPoint pjp, String arg) throws Throwable {
//        System.out.println("name：" + arg);
//        System.out.println("方法环绕start...around");
//        String result = "";
//        try {
//            result = pjp.proceed().toString();
//            System.out.println(result);
//        } catch (Throwable throwable) {
//            throwable.printStackTrace();
//        }
//        System.out.println ("方法环绕end...around");
//        return (String) pjp.proceed ();
//    }
//
//    @After("within(com.sjf.batch.controller.*)")
//    public void after () {
//        System.out.println ("方法执行之后.........");
//    }
//
//    //@AfterReturning(pointcut = "pointCut()", returning = "rst")
//    //public void afterRunning(String rst) {
//    //    if (ObjectUtil.isNull(startTime)) {
//    //        startTime.set(System.currentTimeMillis());
//    //    }
//    //    System.out.println("方法执行完执行...afterRunning");
//    //    logger.info("耗时毫秒：" + (System.currentTimeMillis() - startTime.get()));
//    //    logger.info("返回数据：{}", rst);
//    //    logger.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
//    //}
//
//    @AfterThrowing("within(com.sjf.batch.controller.*Controller)")
//    public void afterThrowing () {
//        System.out.println ("异常出现之后...afterThrowing");
//    }
//}
